﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeInsertNewVendorDataAction : BestLifeDataAction<int>
    {

        private Supplier GvSupplier;
        public BestLifeInsertNewVendorDataAction(Supplier PSupplier)
        {
            GvSupplier = PSupplier;
        }

        public override int Body(SqlConnection PConn)
        {
            try
            {
                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.InsertSupplier";

                
                LvCommand.Parameters.Add(new SqlParameter("@Sup_ID", GvSupplier.Sup_ID.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Contact", GvSupplier.Contact.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Check_Person", GvSupplier.Check_Person.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Check_Type", GvSupplier.Check_Type.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Sup_Name", GvSupplier.Sup_Name.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Sup_Tel", GvSupplier.Sup_Tel.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Sup_mob", GvSupplier.Sup_mob.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Sup_fax", GvSupplier.Sup_fax.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Sup_email", GvSupplier.Sup_email.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Sup_web", GvSupplier.Sup_web.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Sup_Add", GvSupplier.Sup_Add.ToString()));


                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvSupplier.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Date_Create", DateTime.Parse(GvSupplier.Date_Create.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Last_Modify", DateTime.Parse(GvSupplier.Last_Modify.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@User_Modify", GvSupplier.User_Modify.ToString()));





                int LvCount = LvCommand.ExecuteNonQuery();
                return LvCount; 

            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
